#include "explore.h"

QUrl Explore::defaultUrl = QUrl("https://www.baidu.com");

QString Explore::defaultLoadUrl = "https://www.baidu.com";
bool Explore::enableOptimize = true;

Explore::Explore()
{
    // 自定义浏览器配置
    m_downloadManagerWidget.setAttribute(Qt::WA_QuitOnClose, false);


    QObject::connect(
        QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
        &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
    QObject::connect(
        &m_customProfile, &QWebEngineProfile::downloadRequested,
        &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
}

QVector<MainWindow *> Explore::windows()
{
    return this->m_windows;
}

MainWindow *Explore::createWindow(bool offTheRecord)
{
    QWebEngineProfile *profile = offTheRecord ? &m_customProfile : QWebEngineProfile::defaultProfile();
    MainWindow * window = new MainWindow(this, profile);
    // 维护打开的窗口
    m_windows.append(window);
    QObject::connect(window, &QObject::destroyed, [this, window]() {
        m_windows.removeOne(window);
    });
    return window;
}

DownloadManagerWidget& Explore::downloadManagerWidget()
{
    return m_downloadManagerWidget;
}

void Explore::handleShowHistoryWidget()
{
    m_historyWidget.show();
}

